﻿using MQTTnet;
using MQTTnet.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace workstation.utils
{
    public class MqttUntils
    {
        public static async Task Publish(IMqttClient mqttClient, string topic, string content)
        {

            if (string.IsNullOrEmpty(topic))
            {
                return;
            }


            try
            {
                var message = new MqttApplicationMessageBuilder()
                .WithTopic(topic)
                .WithPayload(content)
                .WithExactlyOnceQoS()
                .WithRetainFlag()
                .Build();

                await mqttClient.PublishAsync(message);
            }
            catch (Exception ex)
            {

            }
        }
        public static string getValueFromINI(string paramString)
        {
            string filePath = $"{System.Environment.CurrentDirectory}" + "\\config.ini";
            string value = IniHelper.ReadString(filePath, "USE", paramString, "");
            return value;

        }
    }
}
   